home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / genlin.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  2KB  |  103 lines

  1. /* General line-drawing routine which takes line styles into account */
  2.  
  3. #include "plplot.h"
  4. #include "declare.h"
  5. #include <math.h>
  6.  
  7. static int lastx=-100000, lasty=-100000;
  8.  
  9. void genlin(x1,y1,x2,y2)
  10. int x1,y1,x2,y2;
  11. {
  12.    int nx,ny;
  13.    int modulo, incr, dx, dy, diax, diay, i, temp, x, y;
  14.    int px, py, tstep;
  15.  
  16. /* Check for solid line */
  17.  
  18.    if (nms == 0) {
  19.       grline(x1,y1,x2,y2);
  20.       return;
  21.    }
  22.  
  23. /* Check if pattern needs to be restarted */
  24.  
  25.    if (x1 != lastx || y1 != lasty) {
  26.         curel = 0;
  27.         pendn = 1;
  28.         timecnt = 0;
  29.         alarm = mark[curel];
  30.         if (x1 == x2 && y1 == y2) grline(x1,y1,x2,y2);
  31.    }
  32.  
  33.    lastx = x1;
  34.    lasty = y1;
  35.  
  36.    if (x1 == x2 && y1 == y2) return;
  37.  
  38.    nx = x2 - x1;
  39.    ny = y2 - y1;
  40.  
  41.    if (abs(ny) > abs(nx)) {
  42.         modulo = abs(ny);
  43.         incr   = abs(nx);
  44.         dx     = 0;
  45.         dy     = -1;
  46.         if (ny > 0) dy = 1;
  47.    }
  48.    else {
  49.         modulo = abs(nx);
  50.         incr   = abs(ny);
  51.         dx     = -1;
  52.         if (nx > 0) dx = 1;
  53.         dy     = 0;
  54.    }
  55.  
  56.    diax = -1;
  57.    if (nx > 0) diax = 1;
  58.    diay = -1;
  59.    if (ny > 0) diay = 1;
  60.  
  61.    temp = modulo/2;
  62.    x = x1;
  63.    y = y1;
  64.    i = 1;
  65.  
  66. /* Compute the timer step */
  67.  
  68.    tstep = sqrt(pow((double)(abs(nx)*umx),2.)+
  69.                    pow((double)(abs(ny)*umy),2.))/modulo;
  70.  
  71. loop:
  72.    if (i > modulo) goto exit;
  73.    i = i+1;
  74.    temp = temp+incr;
  75.    px = x;
  76.    py = y;
  77.    if (temp > modulo) {
  78.           temp = temp-modulo;
  79.           x = x + diax;
  80.           y = y + diay;
  81.    }
  82.    else {
  83.           x = x + dx;
  84.           y = y + dy;
  85.    }
  86.    timecnt += tstep;
  87.    if (timecnt >= alarm) {
  88.           plupd();
  89.           if (pendn == 0) grline(lastx,lasty,px,py);
  90.           lastx = x;
  91.           lasty = y;
  92.    }
  93.    goto loop;
  94.  
  95. exit:
  96.    if (pendn != 0) grline(lastx,lasty,x,y);
  97.    lastx = x2;
  98.    lasty = y2;
  99. }
  100.  
  101.  
  102.  
  103.